
#include "opcode.h"

Opcode::Opcode(){
	initOp();
}
void Opcode::initOp() {
	int len;

	 char mp[][2] = {
		0,0,
		0x1,1,
		0x3, 2,
		0x4,0,
		0x5,3,
		0x6,0,
		0x7,0,
		0xa,0,
		0xc,5,
		0xd,3,
		0xf,5,
		0x10, 2,
		0x12, 9,
		0x13, 2,
		0x14, 3,
		0x16, 10,
		0x18, 0,
		0x19, 0,
		0x1A, 2, //Uniquely identifies a choice?
		0x1D, 2,
		0x1E, 1,
		0x1F, 2,
		0x20, 1,
		0x21, 1,
		0x24, 1, //Uniquely identifies a line in a script
		0x26, 1,
		0x27, 1,
		0x28, 1,
		0x37, 2,
		0x40, 8,
		0x41, 5,
		0x45, 2,
		0x46, 1,
		0xFE, 0,
		0xFF, 1

	};
	string ops[] = {
		"end",
		"jump",
		"playBGM",
		"stopBGM",
		"playSFX",
		"stopSFX",
		"waitForSFX",
		"gotoif",
		"bgload",
		"removeBG",
		"fgload",
		"removeFG",
		"multifgload2",
		"multiremoveFG2",
		"multiremoveFG3",
		"multifgload3",
		"hideTextbox",
		"showTextbox",
		"choiceId", //Uniquely identifies a choice?
		"chapterCutin",
		"delay",
		"clock",
		"unknown20",
		"unknown21",
		"scriptLocationId", //Uniquely identifies a line in a script
		"_switch",
		"overlayImage",
		"_switch3",
		"unknown37",
		"specialEffectImage",
		"tweenZoom",
		"specialEffect",
		"unknown46",
		"varop",
		"text"
	} ;
	len = 35;
	op.clear();
	for (int i = 0; i < len; i++)
	{
		op.insert(pair<string,pair<char,char> >(ops[i],pair<char,char>(mp[i][0],mp[i][1])));
	}
	for (int i = 0; i < len; i++)
	{
		rop.insert(pair<char,pair<string,char> >(mp[i][0],pair<string,char>(ops[i],mp[i][1])));
	}


}

bool Opcode::getOpCode(string s){
	opit = op.find(s);
	return opit != op.end();
}

bool Opcode::getOp(char c1) {
	ropit = rop.find(c1);
	return ropit != rop.end();
}

string Opcode::getName() {
	return ropit->second.first;
}

int Opcode::getArgc() {
	return ropit->second.second;
}